package com.mail.server.controller;


import com.mail.model.db.SmsHomeRecommendSubject;
import com.mail.model.vo.PageResult;
import com.mail.server.common.R;
import com.mail.server.service.SmsHomeRecommendSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 首页推荐专题表 前端控制器
 * </p>
 *
 * @author WJZ
 * @since 2022-06-20
 */
@RestController
@RequestMapping("/home/recommendSubject")
public class SmsHomeRecommendSubjectController {

    @Autowired
    private SmsHomeRecommendSubjectService smsHomeRecommendSubjectService;

    @PostMapping("/create")
    public R<String> addSubject(@RequestBody List<SmsHomeRecommendSubject> smsHomeRecommendSubjectList) {
        smsHomeRecommendSubjectService.addSubject(smsHomeRecommendSubjectList);
        return R.success("");
    }

    @PostMapping("/delete")
    public R<String> deleteSubject(@RequestParam("ids") List<Long> ids) {
        smsHomeRecommendSubjectService.deleteSubject(ids);
        return R.success("");
    }

    @GetMapping("/list")
    public R<PageResult> getSubjectByPage(@RequestParam(defaultValue = "1") Long pageNum,
                                          @RequestParam(defaultValue = "10") Long pageSize,
                                          Integer recommendStatus,
                                          String subjectName) {
        PageResult page = smsHomeRecommendSubjectService.getSubjectByPage(pageNum, pageSize, subjectName, recommendStatus);
        return R.success(page);
    }

    @PostMapping("/update/recommendStatus")
    public R<String> updateSubject(@RequestParam("ids") List<Long> ids, @RequestParam("recommendStatus") Integer recommendStatus) {
        smsHomeRecommendSubjectService.updateSubject(ids, recommendStatus);
        return R.success("");
    }

    @PostMapping("/update/sort/{id}")
    public R<String> updateSortSubject(@PathVariable("id") Long id, @RequestParam(required = false) Integer sort) {
        smsHomeRecommendSubjectService.updateSortSubject(id, sort);
        return R.success(null, "修改成功");
    }
}
